/*
 * Copyright (c) 2024 Black Sesame Technologies
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef _DAL_STATUS_
#define _DAL_STATUS_

#include "dal/base_type.h"
#include "dal/qos_policy.h"
#include "dal/instance_handle.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef unsigned long dal_status_mask_t;
typedef unsigned long dal_status_kind_t;
#define DAL_ANY_STATUS (dal_status_mask_t)(0x7fe7u)
#define DAL_NONE_STATUS (dal_status_mask_t)(0)
// StatusKind
#define DAL_INCONSISTENT_TOPIC_STATUS (dal_status_kind_t)(0x0001 << 0)
#define DAL_OFFERED_DEADLINE_MISSED_STATUS (dal_status_kind_t)(0x0001 << 1)
#define DAL_REQUESTED_DEADLINE_MISSED_STATUS (dal_status_kind_t)(0x0001 << 2)
#define DAL_OFFERED_INCOMPATIBLE_QOS_STATUS (dal_status_kind_t)(0x0001 << 5)
#define DAL_REQUESTED_INCOMPATIBLE_QOS_STATUS (dal_status_kind_t)(0x0001 << 6)
#define DAL_SAMPLE_LOST_STATUS (dal_status_kind_t)(0x0001 << 7)
#define DAL_SAMPLE_REJECTED_STATUS (dal_status_kind_t)(0x0001 << 8)
#define DAL_DATA_ON_READERS_STATUS (dal_status_kind_t)(0x0001 << 9)
#define DAL_DATA_AVAILABLE_STATUS (dal_status_kind_t)(0x0001 << 10)
#define DAL_LIVELINESS_LOST_STATUS (dal_status_kind_t)(0x0001 << 11)
#define DAL_LIVELINESS_CHANGED_STATUS (dal_status_kind_t)(0x0001 << 12)
#define DAL_PUBLICATION_MATCHED_STATUS (dal_status_kind_t)(0x0001 << 13)
#define DAL_SUBSCRIPTION_MATCHED_STATUS (dal_status_kind_t)(0x0001 << 14)

typedef unsigned long dal_sample_state_mask_t;
#define DAL_ANY_SAMPLE_STATE (dal_sample_state_mask_t)(0xffff)

typedef unsigned long dal_view_state_mask_t;
#define DAL_ANY_VIEW_STATE (dal_view_state_mask_t)(0xffff)

typedef unsigned long dal_instance_mask_t;
// #define DAL_ANY_INSTANCE_STATE (dal_instance_mask_t)(0xffff)
// #define DAL_NOT_ALIVE_INSTANCE_STATE (dal_instance_mask_t)(0x006)

typedef struct dal_inconsistent_topic_status_t
{
    long total_count;
    long total_count_change;
} dal_inconsistent_topic_status_t;

typedef struct dal_sample_lost_status_t
{
    long total_count;
    long total_count_change;
} dal_sample_lost_status_t;

typedef enum dal_sample_rejected_status_kind_e
{
    DAL_NOT_REJECTED,
    DAL_REJECTED_BY_INSTANCES_LIMIT,
    DAL_REJECTED_BY_SAMPLES_LIMIT,
    DAL_REJECTED_BY_SAMPLES_PER_INSTANCE_LIMIT
} dal_sample_rejected_status_kind_t;

typedef struct dal_sample_rejected_status_t
{
    long total_count;
    long total_count_change;
    dal_sample_rejected_status_kind_t last_reason;
    dal_instance_handle_t last_instance_handle;
} dal_sample_rejected_status_t;

typedef struct dal_liveliness_lost_status_t
{
    long total_count;
    long total_count_change;
} dal_liveliness_lost_status_t;

typedef struct dal_liveliness_changed_status_t
{
    long alive_count;
    long not_alive_count;
    long alive_count_change;
    long not_alive_count_change;
    dal_instance_handle_t last_publication_handle;
} dal_liveliness_changed_status_t;

typedef struct dal_offered_deadline_missed_status_t
{
    long total_count;
    long total_count_change;
    dal_instance_handle_t last_instance_handle;
} dal_offered_deadline_missed_status_t;

typedef struct dal_requested_deadline_missed_status_t
{
    long total_count;
    long total_count_change;
    dal_instance_handle_t last_instance_handle;
} dal_requested_deadline_missed_status_t;

typedef struct dal_qos_policy_count_t
{
    enum dal_qos_policy_e policy_id;
    long count;
} dal_qos_policy_count_t;

typedef SEQUENCE(dal_qos_policy_count_t) QosPolicyCountSeq;

typedef struct dal_offered_incompatible_qos_status_t
{
    long total_count;
    long total_count_change;
    enum dal_qos_policy_e last_policy_id;
    QosPolicyCountSeq policies;
} dal_offered_incompatible_qos_status_t;

typedef struct dal_requested_incompatible_qos_status_t
{
    long total_count;
    long total_count_change;
    enum dal_qos_policy_e last_policy_id;
    QosPolicyCountSeq policies;
} dal_requested_incompatible_qos_status_t;

typedef struct dal_publication_matched_status_t
{
    long total_count;
    long total_count_change;
    long current_count;
    long current_count_change;
    dal_instance_handle_t last_subscription_handle;
} dal_publication_matched_status_t;

typedef struct dal_subscription_matched_status_t
{
    long total_count;
    long total_count_change;
    long current_count;
    long current_count_change;
    dal_instance_handle_t last_publication_handle;
} dal_subscription_matched_status_t;

#ifdef __cplusplus
}
#endif

#endif  // _DAL_STATUS_